<!--
 * @Description: 流程配置组件
 * @Author: DHL
 * @Date: 2022-09-14 11:09:34
 * @LastEditors: DHL
 * @LastEditTime: 2024-02-07 09:26:35
-->
<template>
  <tw-drawer
    v-model="visible"
    title="流程配置"
    size="98%"
    :sticky="false"
    appendToBody
    @close="handleClose"
  >
    <div class="tw-flow-config-wrapper" v-loading="loading">
      <el-tabs v-model="activeName">
        <el-tab-pane label="基础信息" name="basics">
          <div class="form-container">
            <el-form ref="dbFormRef" :model="dbForm" :rules="rules" size="large" label-width="90px">
              <el-form-item label="分类" prop="category">
                <el-cascader
                  v-model="state.category"
                  :options="treeData"
                  :props="{
                    checkStrictly: true,
                    value: 'code',
                    label: 'name',
                    children: 'children'
                  }"
                  filterable
                  clearable
                  placeholder="请选择分类"
                />
              </el-form-item>

              <el-form-item label="名称" prop="name">
                <el-input v-model="dbForm.name" clearable placeholder="请输入名称"></el-input>
              </el-form-item>

              <!-- <el-form-item label="唯一编码" prop="key">
                <el-input v-model="dbForm.key" clearable placeholder="请输入唯一编码"></el-input>
              </el-form-item> -->

              <el-form-item label="资源图标" prop="icon">
                <el-input v-model="dbForm.icon" clearable placeholder="请选择图标">
                  <template #prepend>
                    <el-button>
                      <svg-icon :iconClass="dbForm.icon ? dbForm.icon : ''"></svg-icon>
                    </el-button>
                  </template>
                  <template #append>
                    <el-button @click="handleOpenIcon">
                      <svg-icon iconClass="instagram"></svg-icon>
                    </el-button>
                  </template>
                </el-input>
              </el-form-item>

              <el-form-item label="描述" prop="description">
                <el-input
                  v-model="dbForm.description"
                  clearable
                  placeholder="请输入描述"
                  :row="3"
                  type="textarea"
                ></el-input>
              </el-form-item>

              <el-form-item>
                <el-button type="primary" @click="handleSubmit">提 交</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-tab-pane>
        <el-tab-pane label="流程设计" name="designer" :disabled="!dbForm.id">
          <div class="designer-container">
            <div class="toolbar">
              <div>
                {{ title }}

                <el-tag type="danger" v-if="dbForm.deploymentId">已发布</el-tag>
                <el-tag type="success" v-else>未发布</el-tag>
              </div>
              <div>
                <el-button type="primary" @click="handleCopy(row)"> 复制流程 </el-button>
              </div>
            </div>
            <el-divider />
            <div class="flow-model-designer">
              <flowModelDesigner
                ref="flowModelDesignerRef"
                @save="handleDeploy"
              ></flowModelDesigner>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>

    <selectIcon ref="selectIconRef" :isSelect="true" @selectIcon="handleSelectIcon"></selectIcon>
  </tw-drawer>
</template>

<script src="./useIndex.ts"></script>

<style scoped lang="scss">
  .tw-flow-config-wrapper {
    height: calc(100% - 20px);
    padding: 10px;

    :deep(.el-tabs) {
      height: 100%;

      .el-tabs__content {
        height: calc(100% - 55px);

        .el-tab-pane {
          height: 100%;
        }
      }
    }

    .form-container {
      display: flex;
      justify-content: center;
      align-items: center;

      :deep(.el-form) {
        width: 800px;

        .el-cascader {
          width: 100%;
        }

        .el-button {
          width: 100%;
        }
      }
    }

    .designer-container {
      height: 100%;

      .toolbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 40px;
        padding: 0px 10px;
      }

      .el-divider {
        margin: 0px 0px 10px 0px;
      }

      .flow-model-designer {
        height: calc(100% - 50px);
      }
    }
  }
</style>
